﻿using DDDEF.Domain.Services;
using DDDEF.Infrastructure.Caching;
using DDDEF.Infrastructure.Domain.Musics;
using System.Collections.Generic;
using System.Linq;

namespace DDDEF.Application
{
    public class MusicAppService : IMusicAppService
    {
        #region Fields

        private readonly IStaticCacheManager _cacheManager;

        private readonly IMusicService _musicService;
        #endregion

        #region Construtors

        public MusicAppService(IMusicService musicService, IStaticCacheManager cacheManager)
        {
            this._musicService = musicService;
            this._cacheManager = cacheManager;
        }

        #endregion

        public List<Music> GetAll()
        {
            var cacheKey = "MUSIC_CACHE_KEY";
            var result = _cacheManager.Get<List<Music>>(cacheKey, () =>  _musicService.GetAll().ToList());
            return result;
        }

        public void Insert(Music music)
        {
            _musicService.Insert(music);

        }
    }
}
